package com.net.xpay.common.manager.impl.operator;

import com.google.common.base.Preconditions;
import com.net.common.dao.BasicMapper;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.operator.OperatorUserBindingMapper;
import com.net.xpay.common.domain.operator.OperatorUserBinding;
import com.net.xpay.common.manager.operator.OperatorUserBindingManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
public class OperatorUserBindingManagerImpl extends AbstractManager<OperatorUserBinding> implements OperatorUserBindingManager{

    @Autowired
    private OperatorUserBindingMapper mapper;


    @Override
    protected BasicMapper<Long, OperatorUserBinding> getMapper() {
        return mapper;
    }

    @Override
    public Long byOperatorUserIdCount(Long operatorUserId) {
        Preconditions.checkArgument(operatorUserId != null );

        return mapper.byOperatorUserIdCount(operatorUserId);
    }

    @Override
    public List<OperatorUserBinding> getByOperatorIdList(Long operatorUserId) {
        Preconditions.checkArgument(operatorUserId != null );
        OperatorUserBinding condition = new OperatorUserBinding();
        condition.setOperatorUserId(operatorUserId);
        return listByCondition(condition, new ArrayList<>());
    }

    @Override
    public OperatorUserBinding findByOperatorUserIdAndUserId(Long operatorUserId, Long userId) {
        Preconditions.checkArgument(operatorUserId != null && userId != null );
        OperatorUserBinding condition = new OperatorUserBinding();
        condition.setOperatorUserId(operatorUserId);
        condition.setUserId(userId);
        return getByCondition(condition);
    }

    @Override
    public OperatorUserBinding findByUserId(Long userId) {
        Preconditions.checkArgument(userId != null );
        OperatorUserBinding condition = new OperatorUserBinding();
        condition.setUserId(userId);
        return getByCondition(condition);
    }

    @Override
    public OperatorUserBinding findByOperatorUserId(Long operatorUserId) {
        Preconditions.checkArgument(operatorUserId != null );
        OperatorUserBinding condition = new OperatorUserBinding();
        condition.setOperatorUserId(operatorUserId);
        return getByCondition(condition);
    }
}
